I made a quick code to convert C4d Materials to centileo for a projects I'm working on..
the code just handels color and bump shaders that what I need for my project.. and its not complete working code beacose it's not handling expectations and errors ..etc.
Code |
---|
import c4d # Get material's Vals def MatConvertGet(material1): # Get the material's Name matname = material1.GetName() # Get the material's shaders shaderImg = material1[c4d.MATERIAL_COLOR_SHADER] shaderCol = material1[c4d.MATERIAL_COLOR_COLOR] shaderBumpImg = material1[c4d.MATERIAL_BUMP_SHADER] Bump_stat = material1[c4d.MATERIAL_USE_BUMP] shaderBumpVal = material1[c4d.MATERIAL_BUMP_STRENGTH] Col_texture_path = "" #Get the shader's texture path or color if shaderImg: Col_texture_path = shaderImg[c4d.BITMAPSHADER_FILENAME] Bump_texture_path = "" #Get the shader's texture path or color if shaderBumpImg: Bump_texture_path = shaderBumpImg[c4d.BITMAPSHADER_FILENAME] return {"matname" : matname, "shaderCol" : shaderCol, "Col_texture_path" : Col_texture_path, "Bump_stat" : Bump_stat, "shaderBumpVal" : shaderBumpVal, "Bump_texture_path" : Bump_texture_path,} # Create the centileo Clone def CreatesCNTLmat(matname, shaderCol, Col_texture_path, Bump_stat, shaderBumpVal, Bump_texture_path): # Create the centileo Clone c4d.CallCommand(58000, 1036659) # creat new CNTL material material0 = doc.GetActiveMaterial() # Get the setected new material material0.SetName("SNTL_"+matname) # Color And Texture material0[c4d.IDD_DIFFUSE_COLOR] = shaderCol material0[c4d.IDD_REFL1_ROUGH] = 0.6 if Col_texture_path: Shader1 = c4d.BaseShader(1036812) Shader1[c4d.CNTL_XBITMAP_NAME] = "CColor" Shader1[c4d.CNTL_XBITMAP_FILENAME] = Col_texture_path material0.InsertShader(Shader1) material0[c4d.IDD_DIFFUSE_COLOR_X] = Shader1 # bump map material0[c4d.IDD_TOGGLE_BUMP] = Bump_stat if Bump_stat: material0[c4d.IDD_BUMP] = shaderBumpVal if Bump_stat and Bump_texture_path: Shader2 = c4d.BaseShader(1036812) Shader2[c4d.CNTL_XBITMAP_NAME] = "BBump" Shader2[c4d.CNTL_XBITMAP_FILENAME] = Bump_texture_path material0.InsertShader(Shader2) material0[c4d.IDD_BUMP_X] = Shader2 # Main function def main(): # Get the active material material1 = doc.GetActiveMaterials() for mat in material1: C4D_mat = MatConvertGet(mat) CreatesCNTLmat(C4D_mat["matname"], C4D_mat["shaderCol"], C4D_mat["Col_texture_path"], C4D_mat["Bump_stat"], C4D_mat["shaderBumpVal"], C4D_mat["Bump_texture_path"]) # Update the document c4d.EventAdd() if __name__=='__main__': main() |
so my question is how to replace the old materials by there centileo clones after creating them automatically using python of course
PS: I'm not a programmer by any means, I just know a little of python with some help from chatGPT